Efficient way to write switch statements